<?php
require 'db.php';
if (!isset($_GET['id'])){
    echo "<script>alert('非法进入！')</script>";
    echo "<script>window.location.href='student.php';</script>";
    exit;
}
$id = $_GET['id'];

if (isset($_POST['sub'])){
    $name = $_POST['name'];
    $num = $_POST['num'];
    $subject = $_POST['subject'];
    $major = $_POST['major'];
    
    $sql = "update student set name='".$name."',num='".$num."',subject='".$subject."',major='".$major."' where Id = ".$id;
    $query = mysqli_query($link, $sql);
    if ($query){
        echo "<script>window.location.href='student.php';</script>";
        exit;
    }else{
        echo "<script>alert('更改失败！')</script>";
        echo "<script>window.history.go(-1);</script>";
        exit;
    }
}


$strsql1 = "select * from student where Id = ".$id;
$result1 = mysqli_query($link, $strsql1);
$data_student = mysqli_fetch_row($result1);


$strsql2 = "select * from major";
$result2 = mysqli_query($link, $strsql2);
$data_major = mysqli_fetch_all($result2);




require 'edit.html';

?>